<div class="dialog">
    <table>
        <tbody>
        
            <tr class="prop">
                <td valign="top" class="name">
                    <label for="serialNumber"><g:message code="stockIn.serialNumber" default="Serial Number" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: stockInInstance, field: 'serialNumber', 'errors')}">
                    <g:textField name="serialNumber" value="${stockInInstance?.serialNumber}" />
               </td>

                <td valign="top" class="name">
                    <label for="recordType"><g:message code="stockIn.recordType" default="Record Type" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: stockInInstance, field: 'recordType', 'errors')}">
                    ${stockInInstance?.recordType?.encodeAsHTML()}
                    <g:hiddenField name="recordType.id" value="${stockInInstance?.recordType?.id}" />
                </td>
        
                <td valign="top" class="name">
                    <label for="purchase"><g:message code="stockIn.purchase" default="Purchase" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: stockInInstance, field: 'purchase', 'errors')}">
                    ${stockInInstance?.purchase?.encodeAsHTML()}
                    <g:hiddenField name="purchase.id" value="${stockInInstance?.purchase?.id}" />
                </td>
            </tr>
        
            <tr class="prop">
                <td valign="top" class="name">
                    <label for="dealer"><g:message code="stockIn.dealer" default="Dealer" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: stockInInstance, field: 'dealer', 'errors')}">
                    ${stockInInstance?.dealer?.encodeAsHTML()}
                    <g:hiddenField name="dealer.id" value="${stockInInstance?.dealer?.id}" />
                 </td>
        
                <td valign="top" class="name">
                    <label for="date"><g:message code="stockIn.date" default="Date" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: stockInInstance, field: 'date', 'errors')}">
                    <g:jqDatePicker name="date" value="${stockInInstance?.date}"></g:jqDatePicker>
                </td>
        
                <td valign="top" class="name">
                    <label for="maker"><g:message code="stockIn.maker" default="Maker" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: stockInInstance, field: 'maker', 'errors')}">
                    <g:textField name="makerInput" value="${stockInInstance?.maker?.encodeAsHTML()}"/>
                    <g:hiddenField name="maker.id" value="${stockInInstance?.maker?.id}" />
                 </td>
            </tr>
       
        </tbody>
    </table>
</div>
<g:hiddenField name="approved" value="${stockInInstance?.approved}" />
<div class="list">
    <table>
        <thead>
            <tr>
                <th><g:message code="stockInDetail.serialNumber" default="Serial Number" /></th>
                <th><g:message code="stockInDetail.purchaseDetail" default="Purchase Detail" /></th>
                <th><g:message code="stockInDetail.product" default="Product" /></th>
                <th><g:message code="stockInDetail.life" default="Life" /></th>
                <th><g:message code="stockInDetail.unit" default="Unit" /></th>
                <th><g:message code="stockInDetail.warehouse" default="Warehouse" /></th>
                <th class="number"><g:message code="stockInDetail.quantity" default="Quantity" /></th>
                <th class="number"><g:message code="stockInDetail.used" default="Used" /></th>
                <th class="number"><g:message code="stockInDetail.surplus" default="Surplus" /></th>
                <th class="number"><g:message code="stockInDetail.price" default="Price" /></th>
                <th class="number"><g:message code="stockInDetail.amount" default="Amount" /></th>
                <th class="number"><g:message code="stockInDetail.isOver" default="Over?" /></th>
            </tr>
        </thead>
        <tbody>
        <g:each in="${stockInInstance?.details?.sort{it?.serialNumber}}" status="i" var="stockInDetailInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                <!--serialNumber-->
                <td>
                    ${fieldValue(bean: stockInDetailInstance, field: "serialNumber")}
                    <g:hiddenField name="details[${i}].serialNumber" value="${fieldValue(bean: stockInDetailInstance, field: 'serialNumber')}" />

                    <!--dealer-->
                    <g:set var="dealerId" value="${fieldValue(bean: stockInDetailInstance, field: 'dealer.id')}" />
                    <g:set var="dealerId" value="${dealerId ?: fieldValue(bean: stockInDetailInstance, field: 'dealer')}" />
                    <g:hiddenField name="details[${i}].dealer.id" value="${dealerId}" />
                </td>
                <!--purchase detail-->
                <td>
                    <g:set var="purchaseDetailId" value="${fieldValue(bean: stockInDetailInstance, field: 'purchaseDetail.id')}" />
                    <g:set var="purchaseDetailId" value="${purchaseDetailId ?: fieldValue(bean: stockInDetailInstance, field: 'purchaseDetail')}" />
                    

                    ${include(controller : 'stockInAjax', action : 'purchaseDetail', params : [id : purchaseDetailId] )}
                    <g:hiddenField name="details[${i}].purchaseDetail.id" value="${purchaseDetailId}" />
                </td>
                <!--product-->
                <td>
                    <g:set var="productId" value="${fieldValue(bean: stockInDetailInstance, field: 'product.id')}" />
                    <g:set var="productId" value="${productId ?: fieldValue(bean: stockInDetailInstance, field: 'product')}" />
                   
                    ${include(controller : 'stockInAjax', action : 'product', params : [id : productId] )}
                    
                    
                    <g:hiddenField name="details[${i}].product.id" value="${productId}" />
                </td>
                <!--life-->
                <td>
                    <g:set var="life" value="${new Date() + 3}"></g:set>
                    ${formatDate(format:'yyyy-MM-dd', date : life) }
                    <g:hiddenField name="details[${i}].life" value="date.struct" />
                    <g:hiddenField name="details[${i}].life_year" value="${formatDate(format:'yyyy', date : life) }" />
                    <g:hiddenField name="details[${i}].life_month" value="${formatDate(format:'MM', date : life) }" />
                    <g:hiddenField name="details[${i}].life_day" value="${formatDate(format:'dd', date : life) }" />
                </td>
                <!--unit-->
                <td>
                    ${fieldValue(bean: stockInDetailInstance, field: "unit")}
                    <g:hiddenField name="details[${i}].unit" value="${fieldValue(bean: stockInDetailInstance, field: 'unit')}" />
                </td>
                <!--warehouse-->
                <td>
                    <g:textField name="details[${i}].warehouseInput" value="${stockInDetailInstance?.warehouse?.encodeAsHTML()}"/>
                    <g:hiddenField name="details[${i}].warehouse.id" value="${stockInDetailInstance?.warehouse?.id}" />
                </td>
                <!--quantity-->
                <td class="number">
                    <g:textField name="details[${i}].quantity" value="${fieldValue(bean: stockInDetailInstance, field: 'quantity')}" />
                </td>
                <!--used-->
                <td class="number">
                    ${fieldValue(bean: stockInDetailInstance, field: 'used')}
                    <g:hiddenField name="details[${i}].used" value="${fieldValue(bean: stockInDetailInstance, field: 'used')}" />
                </td>
                <!--surplus-->
                <td class="number">
                    ${fieldValue(bean: stockInDetailInstance, field: 'surplus')}
                    <g:hiddenField name="details[${i}].surplus" value="${fieldValue(bean: stockInDetailInstance, field: 'surplus')}" />
                </td>
                <!--price-->
                <td class="number">
                    ${fieldValue(bean: stockInDetailInstance, field: 'price')}
                    <g:hiddenField name="details[${i}].price" value="${fieldValue(bean: stockInDetailInstance, field: 'price')}" />
                </td>
                <!--amount-->
                <td class="number">
                    ${fieldValue(bean: stockInDetailInstance, field: 'amount')}
                    <g:hiddenField name="details[${i}].amount" value="${fieldValue(bean: stockInDetailInstance, field: 'amount')}" />
                </td>
                <!--Over?-->
                <td class="number">
                    ${fieldValue(bean: stockInDetailInstance, field: 'isOver')}
                    <g:hiddenField name="details[${i}].isOver" value="${fieldValue(bean: stockInDetailInstance, field: 'isOver')}" />
                </td>
            </tr>
        </g:each>
        </tbody>
    </table>
</div>

